/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Recipes")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Recipes.findAll", query = "SELECT r FROM Recipes r ORDER BY r.rName ASC, r.rRev ASC"),
    @NamedQuery(name = "Recipes.findByRid", query = "SELECT r FROM Recipes r WHERE r.rid = :rid"),
    @NamedQuery(name = "Recipes.findByRName", query = "SELECT r FROM Recipes r WHERE r.rName = :rName"),
    @NamedQuery(name = "Recipes.findByRRev", query = "SELECT r FROM Recipes r WHERE r.rRev = :rRev"),
    @NamedQuery(name = "Recipes.findByRgt", query = "SELECT r FROM Recipes r WHERE r.rgt = :rgt"),
    @NamedQuery(name = "Recipes.findByRVol", query = "SELECT r FROM Recipes r WHERE r.rVol = :rVol"),
    @NamedQuery(name = "Recipes.findByYeastName", query = "SELECT r FROM Recipes r WHERE r.yeastName = :yeastName"),
    @NamedQuery(name = "Recipes.findByPTemp", query = "SELECT r FROM Recipes r WHERE r.pTemp = :pTemp"),
    @NamedQuery(name = "Recipes.findByRibu", query = "SELECT r FROM Recipes r WHERE r.ribu = :ribu")})
public class Recipes implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "RID")
    private Integer rid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 80)
    @Column(name = "RName")
    private String rName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RRev")
    private int rRev;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RGT")
    private float rgt;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RVol")
    private float rVol;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PTemp")
    private float pTemp;
    @Basic(optional = false)
    @NotNull
    @Column(name = "RIBU")
    private float ribu;
    @Basic(optional = false)
    @NotNull
    @Column(name = "recipeNotes")
    private String notes;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "rid")
    private Collection<Brews> brewsCollection;
    @OneToMany(mappedBy = "recipeID")
    private Collection<Beer> beerCollection;
    @JoinColumn(name = "YeastName", referencedColumnName = "YID", nullable=true)
    @ManyToOne(optional = true)
    private Yeast yeastName;
    @JoinColumn(name = "mashScheduleID", referencedColumnName = "scheduleID", nullable=true)
    @ManyToOne(optional = true)
    private MashSchedule mashSchedule;
    @JoinColumn(name = "saltRecipeID", referencedColumnName = "recipeSaltID", nullable=true)
    @ManyToOne(optional = true)
    private RecipeSalts recipeSaltID;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTRecipeToMaltBill",
        joinColumns={ @JoinColumn(name="RID", referencedColumnName="RID")},
        inverseJoinColumns={ @JoinColumn(name="maltBillID", referencedColumnName="maltBillID", unique=true)}
    )
    private List<MaltBill> maltBillCollection;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTRecipeToBoilHops",
        joinColumns={ @JoinColumn(name="RID", referencedColumnName="RID")},
        inverseJoinColumns={ @JoinColumn(name="boilHopsID", referencedColumnName="boilHopsID", unique=true)}
    )
    private List<BoilHops> boilHopCollection;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTRecipeToDryHops",
        joinColumns={ @JoinColumn(name="RID", referencedColumnName="RID")},
        inverseJoinColumns={ @JoinColumn(name="dryHopID", referencedColumnName="dryHopID", unique=true)}
    )
    private List<DryHops> dryHopCollection;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTRecipeToAdditives",
        joinColumns={ @JoinColumn(name="RID", referencedColumnName="RID")},
        inverseJoinColumns={ @JoinColumn(name="additiveID", referencedColumnName="additiveID", unique=true)}
    )
    private List<RecipeAdditives> additiveCollection;
    
    public Recipes() {
    }

    public Recipes(Integer rid) {
        this.rid = rid;
    }

    public Recipes(Integer rid, String rName, int rRev, float rgt, float rVol, float pTemp, float ribu) {
        this.rid = rid;
        this.rName = rName;
        this.rRev = rRev;
        this.rgt = rgt;
        this.rVol = rVol;
        this.pTemp = pTemp;
        this.ribu = ribu;
    }

    public Integer getRid() {
        return rid;
    }

    public void setRid(Integer rid) {
        this.rid = rid;
    }

    public String getRName() {
        return rName;
    }

    public void setRName(String rName) {
        this.rName = rName;
    }

    public int getRRev() {
        return rRev;
    }

    public void setRRev(int rRev) {
        this.rRev = rRev;
    }

    public float getRgt() {
        return rgt;
    }

    public void setRgt(float rgt) {
        this.rgt = rgt;
    }

    public float getRVol() {
        return rVol;
    }

    public void setRVol(float rVol) {
        this.rVol = rVol;
    }

    public Yeast getYeastName() {
        return yeastName;
    }

    public void setYeastName(Yeast yeastName) {
        if(yeastName != null && yeastName.getYid() != null){
            this.yeastName = yeastName;
        }
    }

    public float getPTemp() {
        return pTemp;
    }

    public void setPTemp(float pTemp) {
        this.pTemp = pTemp;
    }

    public float getRibu() {
        return ribu;
    }

    public void setRibu(float ribu) {
        this.ribu = ribu;
    }

    public MashSchedule getMashSchedule() {
        return mashSchedule;
    }

    public void setMashSchedule(MashSchedule mashSchedule) {
        if(mashSchedule != null && mashSchedule.getScheduleID() != null){
            this.mashSchedule = mashSchedule;
        }
    }

    public RecipeSalts getRecipeSaltID() {
        return recipeSaltID;
    }

    public void setRecipeSaltID(RecipeSalts recipeSaltID) {
        if(recipeSaltID != null && recipeSaltID.getRecipeSaltID()!= null){
            this.recipeSaltID = recipeSaltID;
        }
    }

    public List<MaltBill> getMaltBillCollection() {
        return maltBillCollection;
    }

    public void setMaltBillCollection(List<MaltBill> maltBillCollection) {
        this.maltBillCollection = maltBillCollection;
    }

    public List<BoilHops> getBoilHopCollection() {
        return boilHopCollection;
    }

    public void setBoilHopCollection(List<BoilHops> boilHopCollection) {
        this.boilHopCollection = boilHopCollection;
    }

    public List<DryHops> getDryHopCollection() {
        return dryHopCollection;
    }

    public void setDryHopCollection(List<DryHops> dryHopCollection) {
        this.dryHopCollection = dryHopCollection;
    }

    public List<RecipeAdditives> getAdditiveCollection() {
        return additiveCollection;
    }

    public void setAdditiveCollection(List<RecipeAdditives> additiveCollection) {
        this.additiveCollection = additiveCollection;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    @XmlTransient
    public Collection<Beer> getBeerCollection() {
        return beerCollection;
    }

    public void setBeerCollection(Collection<Beer> beerCollection) {
        this.beerCollection = beerCollection;
    }

    @XmlTransient
    public Collection<Brews> getBrewsCollection() {
        return brewsCollection;
    }

    public void setBrewsCollection(Collection<Brews> brewsCollection) {
        this.brewsCollection = brewsCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rid != null ? rid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Recipes)) {
            return false;
        }
        Recipes other = (Recipes) object;
        if ((this.rid == null && other.rid != null) || (this.rid != null && !this.rid.equals(other.rid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Recipes[ rid=" + rid + " ]";
    }
    
}
